<template>
  <div>
    <el-form label-width="80" :model="registerForm">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="registerForm.username" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="registerForm.password" type="password" show-password />
      </el-form-item>
      <el-form-item label="确认密码" prop="confirmPassword">
        <el-input v-model="registerForm.confirmPassword" type="password" show-password />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="registerConfirm()">注册</el-button>
        <el-button @click="reset()">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
  import { ref } from 'vue';

  const registerForm = ref({
    username: '',
    password: '',
    confirmPassword: ''
  })

  const emit = defineEmits(['register'])

  const registerConfirm = () => {
    const userInfoStr = JSON.stringify(registerForm.value)
    localStorage.setItem('user', userInfoStr)
    emit('register')
  }

  const reset = () => {
    registerForm.value.username = ''
    registerForm.value.password = ''
    registerForm.value.confirmPassword = ''
  }

</script>
